using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Dodge_Skill : Skill
{
    [Header("Dodge")]
    [SerializeField] private UI_SkillTreeSlot unlockDodgeButton; // 闪避技能解锁按钮
    [SerializeField] private int exasionAmount; // 闪避增加量
    public bool dodgeUnlocked; // 闪避技能是否解锁

    [Header("Mirage dodge")]
    [SerializeField] private UI_SkillTreeSlot unlockMirageDodge; // 幻影闪避技能解锁按钮
    public bool dodgeMirageUnlocked; // 幻影闪避技能是否解锁

    // 重写Start方法
    protected override void Start()
    {
        base.Start();
        // 为解锁按钮添加点击事件监听器
        unlockDodgeButton.GetComponent<Button>().onClick.AddListener(UnlockDodge);
        unlockMirageDodge.GetComponent<Button>().onClick.AddListener(UnlockMirageDodge);
    }

    protected override void CheckUnlock()
    {
        UnlockDodge();
        UnlockMirageDodge();
    }

    // 解锁闪避技能
    private void UnlockDodge()
    {
        if (unlockDodgeButton.unlocked && !dodgeUnlocked)
        {
            player.stats.evasion.AddModifier(exasionAmount); // 增加闪避量
            Inventory.instance.UpdateStatsUI(); // 更新UI
            dodgeUnlocked = true; // 设置闪避技能已解锁
        }
    }

    // 解锁幻影闪避技能
    private void UnlockMirageDodge()
    {
        if (unlockMirageDodge.unlocked)
        {
            dodgeMirageUnlocked = true; // 设置幻影闪避技能已解锁
        }
    }

    // 在闪避时创建幻影
    public void CreateMirageOnDodge()
    {
        if (dodgeMirageUnlocked)
        {
            SkillManager.instance.clone.CreateClone(player.transform, new Vector3(player.facingDir * 2, 0)); // 创建幻影
        }
    }
}